import { defineStore } from 'pinia'
import { ref } from 'vue'
import { SPACE_ROLE_ENUM } from '@/constant/space.ts'
import { getSpaceUserRoleUsingGet } from '@/api/spaceUserController.ts'

export const useSpaceUserRoleStore = defineStore('spaceUserRole', () => {
  const spaceUserRole = ref<string>(SPACE_ROLE_ENUM.VIEWER)

  async function fetchSpaceUserRole(spaceId: number) {
    const res = await getSpaceUserRoleUsingGet({ spaceId: spaceId })
    if (res.data.code === 0 && res.data.data) {
      console.log(res.data.data)
      spaceUserRole.value = res.data.data
    } else {
      console.log("error")
    }
  }

  function getSpaceUserRole() {
    return spaceUserRole.value
  }

  return { spaceUserRole, fetchSpaceUserRole, getSpaceUserRole }
})
